package com.inspection.servlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * Created by zhujun on 2015-6-4.
 */
public class AppServlet extends javax.servlet.http.HttpServlet {

    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        String action = request.getParameter("action");
        String method = request.getParameter("method");

        Class cls = null;
        try {
            cls = Class.forName("com.inspection.action."+action+"Action");
            Object generate = (cls.newInstance());

            Method fundo = generate.getClass().getMethod(method, new Class[] {HttpServletRequest.class, HttpServletResponse.class});
            Object[] arguments = new Object[] {request,response};
            //执行方法
            fundo.invoke(generate , arguments);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        this.doPost(request,response);
    }
}
